extends CharacterBody2D

const SPEED = 400
const BULLET_SCENE = preload("res://Scenes/Bullet.tscn")

@onready var fire_timer = $Timer

var attack_speed = 1
var current_attacks = 0


# 是从属角色Num
var follow_offset: Vector2  # 从属角色的偏移量
	
func _ready():
	add_to_group("player")
	attack_speed =  $"../PlayerManager".attack_speed
	fire_timer.wait_time = attack_speed
	fire_timer.start()
	scale = Vector2(0.75, 0.75)  # 缩小到0.75倍

func _physics_process(delta):
	# 跟随主玩家移动
	var main_player = get_tree().get_nodes_in_group("player")[0]
	if main_player:
		var offset = follow_offset  # 跟随偏移
		position = main_player.position + offset
	move_and_slide()
	
	# 边界限制
	#position = position.clamp(Vector2(0, 0), get_viewport_rect().size)
		

func shoot():
	var bullet = BULLET_SCENE.instantiate()
	bullet.position = position + Vector2(0, -30)
	get_parent().add_child(bullet)
	

func _on_timer_timeout_Fire() -> void:
	shoot()
